<template>
	<view class="pageBg">
		<groupheader noleftIcon title="人脉圈"></groupheader>
		<banner v-if="pageReset" :bannerList="bannerList"></banner>
		<view class="search" v-if="pageReset">
			<typechoice :list="tagList" @choice="choice"></typechoice>
		</view>
		<goodslist v-if="pageReset" :list="list"></goodslist>
	</view>
</template>

<script>
	import banner from '@/components/group/banner/banner.vue';
	import typechoice from '@/components/group/typechoice/typechoice.vue';
	import groupheader from '@/components/group/groupheader/groupheader.vue';
	import { pageScroll } from '@/utils/mixins.js';
	import goodslist from '@/components/group/list/list.vue';
	export default {
		components: {
			banner,
			typechoice,
			goodslist,
			groupheader,
		},
		mixins: [pageScroll],
		data() {
			return {
				bannerList: [],
				tagList: [],
				choiceData: {},
				pageReset: true,
			};
		},
		onLoad() {
			this.initPage();
			this.init();
		},
		async onPullDownRefresh() {
			this.bannerList = [];
			this.tagList = [];
			this.choiceData = {};
			this.pageReset = false;
			await setTimeout(() => {
				this.pageReset = true;
			}, 0);
			this.initPage();
			uni.stopPullDownRefresh();
		},
		methods: {
			choice(data) {
				this.choiceData = data;
				this.reset();
				this.init();
			},
			async init() {
				const res = await this.$api.CardBusinessLists({
					...this.page,
					...this.choiceData,
				});
				this.page.count = res.data.count;
				console.log(this.list);
				this.list = [...this.list, ...res.data.list];
			},
			async initPage() {
				const res = await this.$api.Adlists({ pid: 2 });
				this.bannerList = res.data;
				const tagRes = await this.$api.CardBusinessTag();
				this.tagList = tagRes.data;
			},
		},
	};
</script>
<style lang="scss" scoped>
	.pageBg {
	}
</style>
